import React,{Component} from "react";
import {Form, Input,Modal,message} from 'antd';

const FormItem = Form.Item;
class UpdateModel extends Component{
    constructor(props) {
        super(props);
        this.state = {
          loading: false,
          modal: false,
          data:{},
          hints: {},
          validRules: [],
        };
      }


    init = (record) => {
        console.log(record)
        this.setState({
            data:record
        })
    }

    showModal = () => {
      this.setState({
        visible: true,
      });
    }
  
    hideModal = () => {
      this.setState({
        visible: false,
      });
    }

    handChange = (e) => {
        this.setState({
            data:{
                id:this.state.data.id,
                name:e.target.value,
                type:this.state.data.type,
                url:this.state.data.url,
                createdate:this.state.data.createdate
            }
        })
    }


    //修改的操作
    handleOk=(e) => {
        this.setState({
            visible: false,
        });
        fetch('http://localhost:8004/common/sysFile/update', {
            method: 'POST',
            headers: {
              'Content-Type': 'application/json'
            },
            body: JSON.stringify(this.state.data)
          }).then(res=> {
                message.success('修改成功')
                this.props.fetch();
          }).catch(e=>{
                this.setState({
                    visible:false
                })
                message.error('修改失败')
            });
    }


    
    
    render(){

        return(
            <div>
               <Modal
                    title="修改文件名"
                    visible={this.state.visible}
                    onOk={this.handleOk}
                    onCancel={this.hideModal}
                    okText="确认"
                    cancelText="取消"
                >
                <Form layout="vertical">

                    <FormItem label="文件名" className="formitem">
                        <Input className="inputk" autoComplete="off" value={this.state.data.name} onChange={this.handChange}/>
                    </FormItem>

                </Form>
                </Modal>
            </div>
        )
    }

}

const UpdateForm = Form.create({withRef: true})(UpdateModel);

export default UpdateForm;